﻿#ifndef MSG_H
#define MSG_H

#include <QObject>
#include <QByteArray>


enum MsgID : quint8
{
	cmd_unknown = 0x00,

	cmd_HeartBeat = 0x06,

	cmd_TcpData = 0x51,
	cmd_UdpData = 0x52,
};

class Msg : public QObject
{
	Q_OBJECT
public:
	explicit Msg(QObject* parent = nullptr);

	QByteArray msg_data;
	MsgID msgID;
	quint16 Checksum;                             //校验	N-2,N-1	校验和	15-0	uint16 t	0

public:
	static Msg* OnReceiveData(QByteArray dat, int len, int& used, QString& errMsg);
	static Msg* ParseFromByte(QByteArray dat, int len, QString& errMsg);

public:
	virtual int DataLen();
	bool IsValid(QByteArray dat, int len);

	QString CmdIDString();

	virtual QByteArray ToByte();

	virtual	int Parse(QByteArray dat, int dataLen);

	void calcChecksum();


signals:
};

#endif // MSG_H
